<?php 
	class Model_Photo extends Joob_Db_Table {
		
		protected $key = "id";
	
		protected $db = "photos";
        
        public $id, $place_id, $url, $since, $user_id, $description;
        
        public function add(){
        	$this->since = time();
        	return $this->insert('user_id,url,description,since,place_id');
        }
        
        public static function getByPlace($place_id){
        	$review  = new Model_Photo();
        	return $review->search('place_id='.$place_id,'*', 50);
        }
        
		public static function getByUser($place_id){
        	$review  = new Model_Photo();
        	return $review->search('user_id='.$place_id,'*', 50);
        }
        
		public function getNextPlacePhoto(){
        	$next = $this->search('place_id='.$this->place_id.' and id<'.$this->id,'*',1);
        	if(sizeof($next)<=0){
        		return null;
        	}
        	return $next[0];
        }
        
		public function getPrevPlacePhoto(){
			$prev = $this->search('place_id='.$this->place_id.' and id>'.$this->id,'*',1,'id');
			if(sizeof($prev)<=0){
        		return null;
        	}
			return $prev[0];
        }
        
		public function getNextUserPhoto(){
        	$next = $this->search('user_id='.$this->user_id.' and id<'.$this->id,'*',1);
        	if(sizeof($next)<=0){
        		return null;
        	}
        	return $next[0];
        }
        
		public function getPrevUserPhoto(){
			$prev = $this->search('user_id='.$this->user_id.' and id>'.$this->id,'*',1,'id');
			if(sizeof($prev)<=0){
        		return null;
        	}
			return $prev[0];
        }
        
	}
?>